package hot_100;

import java.util.ArrayList;

public class 验证二叉搜索树 {
    public static void main(String[] args) {

    }

    public boolean isValidBST(TreeNode root) {
        return Dfs(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    public boolean Dfs(TreeNode root, long l, long r) {
        if (root == null)
            return true;
        int v = root.val;
        return v > l && v < r && Dfs(root.left, l, v) && Dfs(root.right, v, r);
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
